package com.gmail.dengtao.joe.commons.crypto.cipher;

import java.security.NoSuchAlgorithmException;

import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;

/**
 * Cipher constants.
 * @author <a href="mailto:joe.dengtao@gmail.com">DengTao</a>
 * @version 1.0
 * @since 1.0
 */
class CipherUtils {

	public static final String AES_CBC_NoPadding = "AES/CBC/NoPadding";
	public static final String AES_CBC_PKCS5Padding = "AES/CBC/PKCS5Padding";
	public static final String AES_ECB_NoPadding = "AES/ECB/NoPadding";
	public static final String AES_ECB_PKCS5Padding = "AES/ECB/PKCS5Padding";
	
	public static final String DES_CBC_NoPadding = "DES/CBC/NoPadding";
	public static final String DES_CBC_PKCS5Padding = "DES/CBC/PKCS5Padding";
	public static final String DES_ECB_NoPadding = "DES/ECB/NoPadding";
	public static final String DES_ECB_PKCS5Padding = "DES/ECB/PKCS5Padding";

	public static final String DESede_CBC_NoPadding = "DESede/CBC/NoPadding";
	public static final String DESede_CBC_PKCS5Padding = "DESede/CBC/PKCS5Padding";
	public static final String DESede_ECB_NoPadding = "DESede/ECB/NoPadding";
	public static final String DESede_ECB_PKCS5Padding = "DESede/ECB/PKCS5Padding";
	
	public static final String RSA_ECB_PKCS1Padding = "RSA/ECB/PKCS1Padding";
	public static final String RSA_ECB_OAEPPadding = "RSA/ECB/OAEPPadding";
	
	public static final String BLOWFISH_ECB_NoPadding = "Blowfish/ECB/NoPadding";
	public static final String BLOWFISH_ECB_PKCS5Padding = "Blowfish/ECB/PKCS5Padding";
	
	/** Advanced Encryption Standard as specified by NIST in a draft FIPS. Based on the Rijndael algorithm by Joan Daemen and Vincent Rijmen, AES is a 128-bit block cipher supporting keys of 128, 192, and 256 bits. */
	public static final String AES = "AES";
	/** The block cipher designed by Bruce Schneier. */
	public static final String BLOWFISH = "Blowfish";
	/** The Digital Encryption Standard as described in FIPS PUB 46-2. */
	public static final String DES = "DES";
	/** Triple DES Encryption (DES-EDE). */
	public static final String DESede = "DESede";
	/** The RSA encryption algorithm as defined in PKCS #1. */
	public static final String RSA = "RSA";
	
	/** No mode. */
	public static final String MODE_NONE = "NONE";
	/** Cipher Block Chaining Mode, as defined in FIPS PUB 81. */
	public static final String MODE_CBC = "CBC";
	/** Cipher Feedback Mode, as defined in FIPS PUB 81. */
	public static final String MODE_CFB = "CFB";
	/** Electronic Codebook Mode, as defined in: The National Institute of Standards and Technology (NIST) Federal Information Processing Standard (FIPS) PUB 81, "DES Modes of Operation," U.S. Department of Commerce, Dec 1980. */
	public static final String MODE_ECB = "ECB";
	/** Output Feedback Mode, as defined in FIPS PUB 81. */
	public static final String MODE_OFB = "OFB";
	/** Propagating Cipher Block Chaining, as defined by Kerberos V4. */
	public static final String MODE_PCBC = "PCBC";

	/** No padding. */
	public static final String PADDING_NO = "NoPadding";
	/** The padding scheme described in: RSA Laboratories, "PKCS #5: Password-Based Encryption Standard," version 1.5, November 1993. */
	public static final String PADDING_PKCS5 = "PKCS5Padding";
	/** The padding scheme defined in the SSL Protocol Version 3.0, November 18, 1996, section 5.2.3.2 (CBC block cipher). */
	public static final String PADDING_SSL3 = "SSL3Padding";
	
	/**
     * Returns a Mac object that implements the specified Cipher transformation. 
     *
     * @param transformation
     * 	the name of the transformation, e.g., DES/CBC/PKCS5Padding. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard transformation names. 
     * @return An Cipher instance.
     * @see Cipher#getInstance(String)
     * @throws IllegalArgumentException
     *             when a {@link NoSuchAlgorithmException} or {@link NoSuchPaddingException} is caught.
     */
    public static Cipher getCipher(String transformation) {
        try {
            return Cipher.getInstance(transformation);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e);
        } catch (NoSuchPaddingException e) {
			throw new IllegalArgumentException(e);
		}
    }
    
}
